package springx.config;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

@Configuration
public class CaptchaConfig {
    @Bean
    public DefaultKaptcha getDefaultKaptcha(){
        //验证码生成器
        DefaultKaptcha defaultKaptcha=new DefaultKaptcha();
        //配置
        Properties properties=new Properties();
        //是否有边框
        properties.setProperty("kaptcha.border","yes");
        //设置边框颜色
        properties.setProperty("kaptcha.border.color","105,179,90");
        //设置验证码
        properties.setProperty("kaptcha.session.key","code");
        //验证码文本字符颜色和样式
        properties.setProperty("kaptcha.textproducer.font.color","blue");
        //设置字体样式
        properties.setProperty("kaptcha.textproducer.font.names","宋体,楷体,微软雅黑");
        //字体大小
        properties.setProperty("kaptcha.textproducer.font.size","30");
        //验证码文字字符内容范围默认是abced2345678gfynmnpwx
        //字符长度默认为5
        properties.setProperty("kaptcha.textproducer.char.length","4");
        //验证码图片宽度默认200
        properties.setProperty("kaptcha.image.width","100");
        //验证码图片高度默认40
        properties.setProperty("kaptcha.image.height","40");
        Config config=new Config(properties);
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }
}
